package com.braska.hewankurban.helper;

import java.net.URI;

import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import android.util.Log;

public class ServiceHelper {

	private URI uri = URI.create("http://192.168.71.1/hewanqurban/service");
	//private URI uri = URI.create("http://192.168.56.1/hewanqurban/service");
	//private URI uri = URI.create("http://hewanqurban.trendvogue.net/service/");
	
	
	private XMLRPCClient client = new XMLRPCClient(uri);

	public boolean login(String Username, String Pass) {

		try {
			String text = (String) client.call("login", Username, Pass);
			if (text.equals("true"))
				return true;
			else {

				return false;
			}
		} catch (XMLRPCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;

	}

	public boolean logindokter(String Nama, int nik) {

		try {
			String text = (String) client.call("logindokter", Nama, nik);
			if (text.equals("true"))
				return true;
			else {

				return false;
			}
		} catch (XMLRPCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;

	}

	public String tambahpemilik(String nama, String alamat, String no_telp) {
		String text = "";
		try {
			text = (String) client.call("tambahpemilik", nama, alamat, no_telp);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return text;

	}

	public String tambahperiksa(String id_user, String id_pemilik_hewan,
			String jenis, String umur, String Berat) {

		String text = "";
		try {
			text = (String) client.call("tambahperiksa", id_user,
					id_pemilik_hewan, jenis, umur, Berat);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.i("ayo metu", e+"");
		}
		Log.e("sukses ra?", text);
		return text;

	}

	public String getuser(String username) {
		String text = "";
		try {
			text = (String) client.call("get_user", username);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return text;

	}

	
	public String getidpemilik(String nama) {
		String text = "";
		try {
			text = (String) client.call("get_id_pemilik", nama);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return text;

	}

	public String gejala() {
		String data = "";
		try {
			data = (String) client.call("get_gejala");
			Log.d("haha", data);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.e("error", e + "");
		}
		return data;

	}

	public String allpenyakit() {
		String data = "";
		try {
			data = (String) client.call("getallpenyakit");
			Log.d("haha", data);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.e("error", e + "");
		}
		return data;

	}

	public String getbobotgejala() {
		String data = "";
		try {
			data = (String) client.call("bobotgejala");
			Log.d("haha", data);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.e("error", e + "");
		}
		return data;

	}

	public String get_penyakit(String id_gejala, String hewan) {

		String data = "";
		try {
			data = (String) client.call("get_penyakitwhereidgejala", id_gejala,
					hewan);
			Log.d("haha", data);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.e("error", e + "");
		}

		return data;

	}

}
